package thread;

import javax.swing.*;
import java.awt.*;

public class Test {
    private JFrame jf = new JFrame();

    private void initUI() {
        this.jf.setTitle("粒子仿真");
        this.jf.setSize(800, 500);
        this.jf.setLayout(new FlowLayout());
        JButton btnStart = new JButton("启动");
        this.jf.add(btnStart);
        this.jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.jf.setVisible(true);

        btnStart.addActionListener(e -> {
            ParticleController pc = new ParticleController(this.jf);
            pc.start();
        });
    }

    private void initFireWork() {
        this.jf.setTitle("群体仿真");
        this.jf.setSize(800, 800);
        this.jf.setLayout(new FlowLayout());
        this.jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        this.jf.setVisible(true);

        // 资源
        FireWork fireWork = new FireWork(this.jf);

        // 线程操作资源
        new Thread(() -> {
            System.out.println("in thread");
            fireWork.draw();
            while (true) fireWork.draw();
        }).start();
    }

    public static void main(String[] args) {
        new Test().initFireWork();
    }
}
